package permission

import (
	"github.com/ifnk/micro-blog/internal/pkg/dbcontext"
	"github.com/ifnk/micro-blog/internal/pkg/log"
	"github.com/ifnk/micro-blog/protobuf/permission_pb"
)

func NewUserRltAuthServer(logger *log.Logger, db *dbcontext.GormDB, jinzhuDB *dbcontext.JinZhuDB) UserRltAuthServer {
	return UserRltAuthServer{
		logger:                               logger,
		db:                                   db,
		UserRltAuthorityServiceDefaultServer: permission_pb.UserRltAuthorityServiceDefaultServer{DB: jinzhuDB.DB},
	}
}

type UserRltAuthServer struct {
	permission_pb.UserRltAuthorityServiceDefaultServer
	logger *log.Logger
	db     *dbcontext.GormDB
}

// 这里是除Crud 以外自己定义的方法
//func (s *UserRltAuthServer) ChangeByUserId(ctx context.Context, in *permission_pb.ChangeByUserIdReq) (*permission_pb.ChangeByUserIdRes, error) {
//	userId := in.GetUserId()
//	authorityIds := in.GetAuthorityIds()
//
//	err := s.db.Delete(&[]permission_pb.SysUserAuthorityORM{}, "sys_user_id = ?", userId).Error
//
//	if err != nil {
//		return nil, err
//	}
//	var list []permission_pb.SysUserAuthorityORM
//	for _, id := range authorityIds {
//		list = append(list, permission_pb.SysUserAuthorityORM{SysUserId: userId, SysAuthorityId: id})
//	}
//	err = s.db.Create(&list).Error
//	if err != nil {
//		return nil, err
//	}
//	return &permission_pb.ChangeByUserIdRes{Success: true}, nil
//}
